<html>
<head><meta charset="utf-8"><title>Warning about `#![no_std]` · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html">Warning about `#![no_std]`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210639680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210639680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210639680">(Sep 19 2020 at 23:08)</a>:</h4>
<p>I'm trying to use a local version of the rust libc crate, and I'm getting this warning about it when building in the context of the compiler. I don't get this warning when building the crate itself:</p>
<div class="codehilite"><pre><span></span><code><span class="n">warning</span>: <span class="nc">unused</span><span class="w"> </span><span class="n">attribute</span><span class="w"></span>
<span class="w">  </span><span class="o">-</span>-&gt; <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">josh</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">rust</span><span class="o">-</span><span class="n">libc</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">lib</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">28</span>:<span class="mi">1</span><span class="w"></span>
<span class="w">   </span><span class="o">|</span><span class="w"></span>
<span class="mi">28</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="cp">#![no_std]</span><span class="w"></span>
<span class="w">   </span><span class="o">|</span><span class="w"> </span><span class="o">^^^^^^^^^^</span><span class="w"></span>
<span class="w">   </span><span class="o">|</span><span class="w"></span>
<span class="w">   </span><span class="o">=</span><span class="w"> </span><span class="n">note</span>: <span class="err">`</span><span class="cp">#[warn(unused_attributes)]</span><span class="err">`</span><span class="w"> </span><span class="n">on</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="n">default</span><span class="w"></span>

<span class="n">warning</span>: <span class="nc">crate</span><span class="o">-</span><span class="n">level</span><span class="w"> </span><span class="n">attribute</span><span class="w"> </span><span class="n">should</span><span class="w"> </span><span class="n">be</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">root</span><span class="w"> </span><span class="n">module</span><span class="w"></span>
<span class="w">  </span><span class="o">-</span>-&gt; <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">josh</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">rust</span><span class="o">-</span><span class="n">libc</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">lib</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">28</span>:<span class="mi">1</span><span class="w"></span>
<span class="w">   </span><span class="o">|</span><span class="w"></span>
<span class="mi">28</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="cp">#![no_std]</span><span class="w"></span>
<span class="w">   </span><span class="o">|</span><span class="w"> </span><span class="o">^^^^^^^^^^</span><span class="w"></span>
</code></pre></div>



<a name="210639689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210639689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210639689">(Sep 19 2020 at 23:09)</a>:</h4>
<p>I don't get why the attribute would be unused. And it <em>is</em> in the root module.</p>



<a name="210640079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210640079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210640079">(Sep 19 2020 at 23:21)</a>:</h4>
<p>Is it included via <code>mod</code> anywhere? I know we do that for stdarch</p>



<a name="210640407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210640407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210640407">(Sep 19 2020 at 23:30)</a>:</h4>
<p>That's a good question.</p>



<a name="210640414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210640414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210640414">(Sep 19 2020 at 23:30)</a>:</h4>
<p>Do you mean with a <code>path</code> directive pointing to <code>src/lib.rs</code>, or by way of <code>mod lib</code> somewhere?</p>



<a name="210640424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210640424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210640424">(Sep 19 2020 at 23:31)</a>:</h4>
<p><code>#[path]</code> I would assume</p>



<a name="210640462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210640462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210640462">(Sep 19 2020 at 23:32)</a>:</h4>
<p>I'm not finding any cases of <code>#[path]</code> like that...</p>



<a name="210640464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210640464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210640464">(Sep 19 2020 at 23:32)</a>:</h4>
<p>Hmm, but then this would also happen without a custom libc</p>



<a name="210640466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210640466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210640466">(Sep 19 2020 at 23:32)</a>:</h4>
<p>Since it has been <code>#[no_std]</code> for a while</p>



<a name="210641440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210641440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210641440">(Sep 20 2020 at 00:07)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> if you can get the failing rustc invocation that should tell you the crate root path</p>



<a name="210641448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210641448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210641448">(Sep 20 2020 at 00:07)</a>:</h4>
<p>I'm a little surprised that error doesn't print it</p>



<a name="210643097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210643097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210643097">(Sep 20 2020 at 01:04)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> It looks like it's an artifact of specifying both <code>#![no_core]</code> and <code>#![no_std]</code>.  <code>no_core</code> implies <code>no_std</code>, so the <code>no_std</code> attribute isn't actually used. Changing libc to use something like <code>#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]</code> might avoid it.</p>
<p>As for the "crate level" warning, I think that is a bug in the unused_attributes code.  I'm guessing it assumes that all <code>CrateLevel</code> attributes are always used, and issues that warning  unconditionally without looking that it is already in the crate root. It's not really clear why it was written that way.</p>



<a name="210646275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Warning%20about%20%60%23%21%5Bno_std%5D%60/near/210646275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Warning.20about.20.60.23!.5Bno_std.5D.60.html#210646275">(Sep 20 2020 at 02:57)</a>:</h4>
<p><span class="user-mention" data-user-id="120518">@Eric Huss</span> That makes sense. Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>